package calao.contact.client;

import java.util.Iterator;
import java.util.Vector;

import calao.client.ui.NumberedListBox;

public class ContactGroupBox 
extends NumberedListBox
{

	final ContactMod mod = ContactMod.instance;

	Vector data = new Vector();
	
	public ContactGroupBox(boolean multiple)
	{
		super(multiple? CHECK_LIST : DROPDOWN_LIST);
		Iterator iter = mod.listGroups();
		while (iter.hasNext()) data.add(iter.next());
	}
	
	public ContactGroupBox()
	{
		this(true);
	}

	public void setNumberSelected(long number)
	{
		if (mod.getContact((int)number)==null) {
			data.add(getFirstSortableItem(), new Group((int)number));
			setFirstSortableItem(getFirstSortableItem()+1);
		}
		super.setNumberSelected(number);
	}
	
	protected int getItemCount() 
	{
		return data.size();
	}

	protected long getItemNumber(int index) 
	{
		return getGroup(index).id;
	}
	
	Group getGroup(int index)
	{
		return (Group)data.get(index);
	}

	protected String getItemText(int index) 
	{
		return getGroup(index).name;
	}

}
